package com.XuYixuan;

class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int ptr1 = 0, ptr2 = 0;
        int[] nums = new int[m + n];
        int cur;
        while(ptr1 < m && ptr2 < n){
            if(nums1[ptr1] < nums2[ptr2]){
                nums[ptr1 + ptr2] = nums1[ptr1];
                ptr1++;
            }else{
                nums[ptr1 + ptr2] = nums2[ptr2];
                ptr2++;
            }
        }

        while(ptr2 < n){
            nums[ptr1 + ptr2] = nums2[ptr2];
            ptr2++;
        }
        while(ptr1 < m){
            nums[ptr1 + ptr2] = nums1[ptr1];
            ptr1++;
        }

        for(int i = 0 ; i < m + n ; i++){
            nums1[i] = nums[i];
        }
    }
}


public class Main {
    public static void main(String[] args) {
        int[] nums1 = {1,2,3,0,0,0};
        int m = 3;
        int[] nums2 = {2,5,6};
        int n = 3;
        Solution solution = new Solution();
        solution.merge(nums1, m, nums2, n);
    }
}